#pragma once

#include "common.h"

template <class KeyType, class ObjType>
class CBaseObjContainer
{
protected:
	CBaseObjContainer()
	{
		memset( &m_defaultObj,0, sizeof(ObjType) );
	}
	CBaseObjContainer( const CBaseObjContainer& );
	CBaseObjContainer& operator =(const CBaseObjContainer&);
	typedef std::map<KeyType, ObjType> ObjMap;
	virtual ~CBaseObjContainer()
	{
	}
public:
	ObjType &Find( KeyType &key )
	{
		ObjMap::iterator iter = m_objMap.find(key);
		if( iter == m_objMap.end() )
			return m_defaultObj;
		return iter->second;
	}
	bool Have( KeyType &key )
	{
		ObjMap::iterator iter = m_objMap.find(key);
		if( iter == m_objMap.end() )
			return false;
		return true;
	}
	bool Remove( KeyType &key )
	{
		ObjMap::iterator iter = m_objMap.find(key);
		if( iter == m_objMap.end() )
			return false;
		m_objMap.erase( iter );
		return true;
	}
	void Insert( KeyType &key, ObjType &obj )
	{
		m_objMap[key] = obj;
	}
private:
	ObjMap m_objMap;
	ObjType m_defaultObj;
};